<?php

/**
 * Small session wrapper
 *
 * Checks in the constructor if the session is allready started. If not it tries to start it
 */
class Session
{

    public function __construct($regenerate = true) {
        $id = session_id();
        if (empty($id)) {
            session_start();
        }
    }

    public function __get($name) {
        if (isset($_SESSION[$name])) {
            return $_SESSION[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value) {
        $_SESSION[$name] = $value;
    }

    public function __unset($name) {
        if (isset($_SESSION[$name])) {
            unset($_SESSION[$name]);
        }
    }

    public function destructSession() {
        $_SESSION = array();
        session_destroy();
        setcookie(session_name(), '', time() - 3600);
    }

}